package com.example.bluetoothdemo;

import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;

public class Application extends android.app.Application {
    private final static String TAG = Application.class.getSimpleName();

    private static Application instance;
    public static Context gContext;

    @Override
    public void onCreate() {
        super.onCreate();
        gContext = getApplicationContext();
    }

    public static synchronized Application getInstance() {
        if (instance == null) {
            instance = new Application();
        }
        return instance;
    }

    public static synchronized Context getContext() {
        return gContext;
    }

    //判断服务是否启动
    private static boolean isServiceRunning(Class<?> serviceClass) {
        if (Application.getContext() != null){
            ActivityManager manager = (ActivityManager) Application.getContext().getSystemService(Context.ACTIVITY_SERVICE);
            for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
                if (serviceClass.getName().equals(service.service.getClassName())) {
                    return true;
                }
            }
        }
        return false;
    }
}